

#pragma once

#include <cstring>
#include <functional>
#include <mutex>
#include <thread>
#include <memory>
#include <condition_variable>
#include <vector>
#include <map>

class ThreadPoolManager;

class ThreadQueue
{
public:
	ThreadQueue();
	~ThreadQueue();
private:
	friend class ThreadPoolManager;
private:
	std::vector<std::function<void()>> m_task_vec;
	std::thread m_thread;
	std::mutex  m_mutex;
	std::condition_variable m_cond;
	int m_thread_index;
};

class ThreadPoolManager
{
public:
	ThreadPoolManager(int size = 10);
	void PushTask(std::function<void()> && func_task);
	void PushTaskByIndex(int index, std::function<void()> && func_task);
	void Run();
private:
	void RunThreadQueue(int index);
private:
	std::vector<std::shared_ptr<ThreadQueue>> m_thread_queue_vec;
	int m_size;
	bool m_is_running{false};
private:
	int m_push_index;
};